home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / Simple Animation.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  3.6 KB  |  102 lines

  1. //////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED
  4. // Copyright 2002 Adobe Systems Incorporated
  5. // All Rights Reserved
  6. //
  7. // NOTICE:  Adobe permits you to use, modify, and
  8. // distribute this file in accordance with the terms
  9. // of the Adobe license agreement accompanying it.
  10. // If you have received this file from a source
  11. // other than Adobe, then your use, modification,
  12. // or distribution of it requires the prior
  13. // written permission of Adobe.
  14. //
  15. //////////////////////////////////////////////////
  16.  
  17. //////////////////////////////////////////////////
  18. // Simple Animation.js
  19. //
  20. // DESCRIPTION
  21. //
  22. // This script demonstrates how to move an object an additional 
  23. // 100,100 pixels across 12 frames.
  24. //
  25. // HOW TO USE
  26. //
  27. // Create any object and select it in the Composition.
  28. // Select Automation > Run Automation Scripts > Simple Animation.js
  29. // Click on Preview Mode to view the object animation !
  30. //
  31. //////////////////////////////////////////////////
  32.  
  33. // Main Code [Execution of script begins from here]
  34.  
  35. // Check if any composition is open
  36. if(application.compositions.length > 0){
  37.     comp = application.currentComposition;
  38.     if(comp.selection.length >= 1){ // Checks if at least one object is selected
  39.         var objs = comp.selection; // Store all selected objects in the array objs
  40.         
  41.         for(var i=0 ; i < objs.length ; i++){
  42.             // Assign the objects in objs, one by one to target and apply complex animation to them
  43.             target = objs[i]; 
  44.             application.currentComposition.saveSelection(); // saves the current selection
  45.             simpleAnimation(target, 100, 100, 12); // Function complexAnimation called
  46.             application.currentComposition.restoreSelection(); // restores the saved selection
  47.         }
  48.     }
  49.     else{ // If no objects are selected brings the Console window up 
  50.         Console.show();
  51.         // Writes to the Console
  52.         Console.write("Please select the objects to apply the Animation and run the script again.\n");
  53.     }
  54. }
  55. else{// if no composition open
  56.     // opens a new composition
  57.     comp = application.newComposition();
  58.     Console.show();
  59.     Console.write("New Composition opened\nPlease create and select the objects to apply the Animation and run the script again.\n");
  60. }
  61.  
  62.  
  63. // Add your own functions here
  64.  
  65. //////////////////////////////////////////////////
  66. //
  67. // simpleAnimation:
  68. // Changes the location of the target 
  69. //
  70. // targets: the object whose location we want to change
  71. // xDelta: change in x location
  72. // yDelta: change in y location
  73. // frames: Total frames across which the object moves.
  74. //
  75. //////////////////////////////////////////////////
  76.  
  77. function simpleAnimation(target, xDelta, yDelta, frames)
  78. {
  79.     var x_original; // variable for the original x position
  80.     var y_original; // variable for the original y position
  81.     var frame0; // The initial frame to start the animation from -- also the current frame
  82.  
  83.     frame0 = target.startFrame; // Take the current frame value and store it
  84.     x_original = target.position.x; // store original x position
  85.     y_original = target.position.y; // store original y position
  86.  
  87.     target.stopwatch.position = true; // turn on the stopwatch for position
  88.     
  89.     // Note: The initial positions are not stored by turning on the stopwatch.
  90.     // The stopwatch only records changes AFTER it's been turned on.
  91.     
  92.     target.position.x = x_original;
  93.     target.position.y = y_original;
  94.  
  95.     target.currentFrame = frame0+frames;// Advance to frame0+frames, here 0+12=12
  96.     // frame0 is 0 assuming the current Time Marker/Indicator was at position 0 when you executed
  97.     // this script.
  98.     target.position.x += xDelta; // Add pixels to be advanced
  99.     target.position.y += yDelta;
  100. }
  101.  
  102.